package com.acme.bankapp.domain.accounts;

/**
 * 
 * Represents an account WITH overdraft.
 * 
 * Holds balance info.
 * Ensures safety of business rules.
 *
 */
public class CheckingAccount extends AbstractAccount {
	protected double overdraft;

	/**
	 * Creates a Checking account with zero balance and a specified overdraft.
	 */
	public CheckingAccount(double overdraft) {
		balance = 0.;
		this.overdraft = overdraft;
	}


	/**
	 * Withdraws amount from account, considering overdraft.
	 * @param amount amount to be withdrawn.
	 * @return true if amount positive and amount is small enough to be withdrawn , false otherwise.
	 */
	public boolean withdraw(double amount) {
		if (amount > 0.) {
			if (balance - amount > -overdraft) {
				balance -= amount;
				return true;				  
			}
		}
		return false;
	}

	/**
	 * Adds amount to account's balance.
	 * @param amount amount to be deposited.
	 * @return true if amount positive, false otherwise.
	 */
	public boolean deposit(double amount) {
		if (amount > 0.) {
			balance += amount;
			return true;
		}
		return false;
	}

	public double getBalance() {
		return balance;
	}

	/**
	 * Returns balance as String.
	 */
	@Override
	public String toString() {
		return "" + getBalance();
	}

}
